import express from "express";
var router = express.Router();

import { DB } from "../api.js";
var nedb = new DB("./nedb/db/sys.db");
console.log(nedb);

//查询单条数据
router.get("/bridata-system/menu/routes", function (req, res, next) {
  res.json({
    code: 200,
    success: true,
    data: [
      {
        id: "1496416202801213442",
        parentId: "0",
        code: "vs",
        name: "可视化平台",
        alias: "vs",
        path: "/",
        source: "iconfont iconicon_glass",
        sort: 4,
        category: 1,
        action: 0,
        isOpen: 1,
        remark: "",
        isDeleted: 0,
        isApp: 1,
        isSystem: 0,
        children: [
          {
            id: "1496438801593724929",
            parentId: "1496416202801213442",
            code: "vs_app",
            name: "应用管理",
            alias: "vs_app",
            path: "/visual/project",
            source: "iconfont iconicon_work",
            sort: 1,
            category: 1,
            action: 0,
            isOpen: 1,
            remark: "",
            isDeleted: 0,
            isApp: 0,
            isSystem: 0,
            parentName: null,
            categoryName: null,
            actionName: null,
            isOpenName: null,
          },
          {
            id: "1496438935656263681",
            parentId: "1496416202801213442",
            code: "vs_scene",
            name: "场景管理",
            alias: "vs_scene",
            path: "/visual/scene",
            source: "iconfont iconicon_shakehands",
            sort: 2,
            category: 1,
            action: 0,
            isOpen: 1,
            remark: "",
            isDeleted: 0,
            isApp: 0,
            isSystem: 0,
            parentName: null,
            categoryName: null,
            actionName: null,
            isOpenName: null,
          },
          {
            id: "1496439069156765697",
            parentId: "1496416202801213442",
            code: "vs_collect",
            name: "精品案例",
            alias: "vs_collect",
            path: "/visual/collect",
            source: "iconfont iconicon_cspace",
            sort: 3,
            category: 1,
            action: 0,
            isOpen: 1,
            remark: "",
            isDeleted: 0,
            isApp: 0,
            isSystem: 0,
            parentName: null,
            categoryName: null,
            actionName: null,
            isOpenName: null,
          },
        ],
        parentName: null,
        categoryName: null,
        actionName: null,
        isOpenName: null,
      },
    ],
    msg: "操作成功",
  });
});

//查询列表数据
router.post("/bridata-auth/oauth/token", function (req, res, next) {
  res.json({
    tenant_id: "vs000001",
    user_id: "1503286747084406785",
    dept_id: "1503286746883080193",
    post_id: "1503286746950189058",
    role_id: "1503286746014859265",
    oauth_id: null,
    account: "admin",
    user_name: "admin",
    nick_name: "admin",
    role_name: "admin",
    avatar: "",
    access_token:
      "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJpc3N1c2VyIiwiYXVkIjoiYXVkaWVuY2UiLCJ0ZW5hbnRfaWQiOiJ2czAwMDAwMSIsInJvbGVfbmFtZSI6ImFkbWluIiwicG9zdF9pZCI6IjE1MDMyODY3NDY5NTAxODkwNTgiLCJ1c2VyX2lkIjoiMTUwMzI4Njc0NzA4NDQwNjc4NSIsInJvbGVfaWQiOiIxNTAzMjg2NzQ2MDE0ODU5MjY1IiwidXNlcl9uYW1lIjoiYWRtaW4iLCJuaWNrX25hbWUiOiJhZG1pbiIsImRldGFpbCI6eyJ0eXBlIjoid2ViIn0sInRva2VuX3R5cGUiOiJhY2Nlc3NfdG9rZW4iLCJkZXB0X2lkIjoiMTUwMzI4Njc0Njg4MzA4MDE5MyIsImFjY291bnQiOiJhZG1pbiIsImNsaWVudF9pZCI6InNhYmVyIiwiZXhwIjoxNjUyODY3MzA4LCJuYmYiOjE2NTI4NjM3MDh9.dXiic-d1iP_vjXxahywgMzNRziddyj3w-CJgu5cAIf4pPJiB6foeozpkbDZIE-Vk2D8wuv_gbkJ23idBnaEPmw",
    refresh_token:
      "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJpc3N1c2VyIiwiYXVkIjoiYXVkaWVuY2UiLCJ1c2VyX2lkIjoiMTUwMzI4Njc0NzA4NDQwNjc4NSIsInRva2VuX3R5cGUiOiJyZWZyZXNoX3Rva2VuIiwiY2xpZW50X2lkIjoic2FiZXIiLCJleHAiOjE2NTM0Njg1MDgsIm5iZiI6MTY1Mjg2MzcwOH0.hRwpagRHPoLafH4uJWfEPQeBGfc2-YSVufQBmmk8ZuIq-QmuBnUIGH-H4tTdN5F80CKYOJGVkLzk3L-fBnvDuQ",
    token_type: "bearer",
    expires_in: 3600,
    detail: { type: "web" },
    license: "powered by bridata",
  });
});

//保存数据
router.post("/saveOrUpdate", function (req, res, next) {
  var params = req.body;
  nedb.app[params._id ? "update" : "insert"](params, {})
    .catch((result) => result)
    .then((result) => res.json(result));
});

export default router;
